/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication7;

import java.io.FileReader;
import java.util.HashMap;
import java.util.Map;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;

public class ConfigImporter1 {

    public static Map<String, String> map = new HashMap<String, String>();

    public static void main(String[] args) {
        try {
            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
            Document doc = dBuilder.parse(new InputSource(new FileReader("drugs.xml")));

            doc.getDocumentElement().normalize();

            NodeList nList = doc.getElementsByTagName("code");

            for (int i = 0; i < nList.getLength(); i++) {
                Node nNode = nList.item(i);
                if (nNode.getNodeType() == Node.ELEMENT_NODE) {
                    Element eElement = (Element) nNode;
                    map.put(eElement.getAttribute("value"), eElement.getAttribute("displayName"));
                    
                }
            }
            }  catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(map);
        System.out.println(map.size());
    }
}